/*
 * Created on Jan 18, 2004
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package com.unash.asn;

import com.unash.util.Consts;
import junit.framework.TestCase;
import junitx.framework.ArrayAssert;

/**
 * @author ujoshi
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class BerEncoderTest implements Consts{



	public void testItuOid() {
		int[] ituTOid = new int[] { 0 };
		byte[] expectedValue = new byte[] {(byte) 0 };
		AsnObjectIdentifier objIdentifier = new AsnObjectIdentifier(ituTOid);
		byte[] encodedString = BerEncoder.encodeObjectIdentifier(objIdentifier);
		ArrayAssert.assertEquals(encodedString, expectedValue);
	}

	public void testIsoOid() {
		int[] isoOid = new int[] { 1 };
		byte[] expectedValue = new byte[] {(byte) 40 };
		AsnObjectIdentifier objIdentifier = new AsnObjectIdentifier(isoOid);
		byte[] encodedString = BerEncoder.encodeObjectIdentifier(objIdentifier);
		ArrayAssert.assertEquals(encodedString, expectedValue);
	}

	public void testAsn1BookOid() {
		int[] asnBookOid = new int[] { 1, 2, 250, 1, 16, 9};
		byte[] expectedValue = new byte[] {(byte) 42, (byte)0x81, (byte)122, (byte)1, (byte)16, (byte)9 };
		AsnObjectIdentifier objIdentifier = new AsnObjectIdentifier(asnBookOid);
		byte[] encodedString = BerEncoder.encodeObjectIdentifier(objIdentifier);
		ArrayAssert.assertEquals(encodedString, expectedValue);
	}
	
	public void testEncodeBoolean(){
		byte[] expectedTrueValue = new byte[]{BER_TRUE};
		byte[] expectedFalseValue = new byte[]{BER_FALSE};
		
		AsnBoolean asnBooleanTrue = new AsnBoolean(true);
		byte[] encodedValue = BerEncoder.encodeBoolean(asnBooleanTrue);
		ArrayAssert.assertEquals(expectedTrueValue,encodedValue);
		
		AsnBoolean asnBooleanFalse = new AsnBoolean(false);
		encodedValue = BerEncoder.encodeBoolean(asnBooleanFalse);
		ArrayAssert.assertEquals(expectedFalseValue,encodedValue);
	}//testEncodeBoolean
	
	public void testEncodeInteger(){
		byte[] expectedValue = new byte[]{(byte)0x96,0x46};
		
		AsnInteger asnInteger = new AsnInteger(-27066);
		byte[] encodedValue = BerEncoder.encodeInteger(asnInteger);
		ArrayAssert.assertEquals(expectedValue,encodedValue);
		
	}//testEncodeInteger
	
	public void testEncodeBitString(){
		byte[] expectedValue = new byte[]{0x03,(byte)0xB7,0x58};
		
		AsnBitString asnBitString = new AsnBitString(new byte[]{(byte)0xB7,0x58},13);
		byte[] encodedValue = BerEncoder.encodeBitString(asnBitString);
		ArrayAssert.assertEquals(expectedValue,encodedValue);
	}//testEncodeBitString
	
	public void testEncodeOctetString(){
		byte[] expectedValue = new byte[]{(byte)0xB7,0x58};
		
		AsnOctetString asnOctetString = new AsnOctetString(new byte[]{(byte)0xB7,0x58});
		byte[] encodedValue = BerEncoder.encodeOctetString(asnOctetString);
		ArrayAssert.assertEquals(expectedValue,encodedValue);
		
	}//testEncodeOctetString
	
	//TODO: test encoding of visible string
	public void testEncodeVisibleString(){
		byte[] expectedValue = new byte[]{};
		
		AsnVisibleString asnVisibleString = new AsnVisibleString("TestVisibleString");
	}//testEncodeVisibleString
	
}
